package cn.cimoc.controller;

import cn.cimoc.annotation.ResponseResult;
import cn.cimoc.mapper.DistrictMapper;
import cn.cimoc.model.dto.output.DistrictDTO;
import cn.cimoc.model.po.TDictDistrict;
import cn.cimoc.util.CommonUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("/districts")
@ResponseResult
public class DistrictController {

    @Autowired
    DistrictMapper mapper;

    @GetMapping("/")
    public List<DistrictDTO> getDistrict(String parent) {
        QueryWrapper<TDictDistrict> wrapper = new QueryWrapper<>();
        wrapper.eq("parent", parent);
        List<TDictDistrict> data = mapper.selectList(wrapper);
        return CommonUtils.getMapperFacade().mapAsList(data, DistrictDTO.class);
    }
}
